package cn.rengy.web.framework.datagrid.web;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import cn.rengy.lang.ResultEntity;
import cn.rengy.tool.core.util.ExceptionPrintUtils;
import cn.rengy.web.framework.datagrid.service.DataGridService;


/**
 * 处理easyui datagrid请求
 * 
 */
public class BaseGridController {
	private static Logger logger = LoggerFactory.getLogger(BaseGridController.class);
	
	@Autowired
	private DataGridService dataGridService;
	/**
	 * 列表查询
	 * @param sqlid
	 * @param paramMap
	 * @return
	 */
	public Map<String,Object> gridList (String sqlid,Map<String,Object> paramMap){
		logger.info(paramMap.toString());
		try{
			return dataGridService.query(sqlid, paramMap);
		}catch(Exception e){
			logger.error(ExceptionPrintUtils.getTrace(e));
		}
		return null;
	}
	/**
	 * 列表保存
	 * @param sqlid
	 * @param paramMap
	 * @return
	 */
	public ResultEntity<?> gridSave(String sqlid,Map<String,Object> paramMap){
		dataGridService.save(sqlid, paramMap);
		return ResultEntity.ok();
	}
	/**
	 * 列表保存
	 * @param sqlid
	 * @param paramMap
	 * @return
	 */
	public ResultEntity<?> treeGridSave(String sqlid,Map<String,Object> paramMap){
		dataGridService.treeGridSave(sqlid, paramMap);
		return ResultEntity.ok();
	}
	
	/**
	 * 字段信息查询v2版本
	 * @param tablename
	 * @return
	 */
	public ResultEntity<?> gridColumn(Long page_id){
		return ResultEntity.ok(dataGridService.queryGridColumnV2(page_id));
	}
}
